package com.ideal.frame.sys.service;

import com.ideal.frame.jpa.DSLRequest;
import com.ideal.frame.jpa.JpaRepositoryImpl;
import com.ideal.frame.sys.entity.QSysAddress;
import com.ideal.frame.sys.entity.QSysIndustryClassification;
import com.ideal.frame.sys.entity.SysAddress;
import com.ideal.frame.sys.entity.SysIndustryClassification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class SysIndustryClassificationService {
    @PersistenceContext
    protected EntityManager entityManager;
    private JpaRepositoryImpl<SysIndustryClassification, Long> sysAddressLongJpaRepository;

    QSysIndustryClassification qSysIndustryClassification = QSysIndustryClassification.sysIndustryClassification;

    @PostConstruct
    public void initRepo() {
        sysAddressLongJpaRepository = new JpaRepositoryImpl<>(SysIndustryClassification.class, entityManager);
    }

    public List<SysIndustryClassification> listIndustryClassification(Long id) {
        DSLRequest request = new DSLRequest();
        request.addWhere(qSysIndustryClassification.parentId.eq(id));
        request.addWhere(qSysIndustryClassification.delFlag.isFalse());
        return sysAddressLongJpaRepository.findAll(request);
    }
}